package com.wnx.db;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import com.wnx.entity.Collect;
import com.wnx.entity.Goods;
import com.wnx.util.HibernateUtil;

public class CollectDao {
	public String saveG(Collect collect){
		 String message = "error";
		 Session session = new HibernateUtil().getSession();
		 Transaction transaction = session.beginTransaction();
		 session.save(collect);
		 transaction.commit();
		 session.close();
		 message = "success";
		 return message;
	 }
	public List getCollectStateBygid(Collect collect){
		Session session = new HibernateUtil().getSession();
		Transaction transaction = session.beginTransaction();
		String hql = "from Collect where gid=? and uid=?";
		Query<Collect> query = session.createQuery(hql,Collect.class);
		query.setParameter(0, collect.getGid());
		query.setParameter(1, collect.getUid());
		List list=query.list();
        transaction.commit();
        session.close();
		return list;
	}
	public Collect delCollectBygid(Collect collect){
		Session session = new HibernateUtil().getSession();
		Transaction transaction = session.beginTransaction();
		String hql = "delete from Collect where gid=? and uid=?";
		Query query = session.createQuery(hql);
		query.setParameter(0, collect.getGid());
		query.setParameter(1, collect.getUid());
		query.executeUpdate();
		transaction.commit();
        session.close();
        return collect;
	}
	public List selCollectByuid(Collect collect){
		Session session = new HibernateUtil().getSession();
		Transaction transaction = session.beginTransaction();
		String hql = "from Collect where uid=?";
		Query<Collect> query = session.createQuery(hql,Collect.class);
		query.setParameter(0, collect.getUid());
		List list=query.list();
        transaction.commit();
        session.close();
		return list;
	}
	public Collect delCollectByid(Collect collect){
		Session session = new HibernateUtil().getSession();
		Transaction transaction = session.beginTransaction();
		String hql = "delete from Collect where id=?";
		Query query = session.createQuery(hql);
		query.setParameter(0, collect.getId());
		query.executeUpdate();
		transaction.commit();
        session.close();
        return collect;
	}
}
